import { legacy_createStore as createStore,combineReducers } from 'redux'
import {INCREMENT,DECREMENT} from '../constants/index'

const countState = {
    count:1
}
const loginState = {
    account :'test',
    password:666
}

const countReducers = (state = countState,action) => {
    const {type,payload} = action
    switch(type){
        case INCREMENT:
            return {...state,count:state.count+payload}
        case DECREMENT:
            return {...state,count:state.count-payload}
        default:
            return state
    }
}

const loginReducer = (state=loginState,action) => {
    const {type,payload} =action
    switch(type) {
        case 'CHANGE_ACCOUNT' :
            return {...state,account:payload}
        default:
            return state
    }
}

export const rootReducers= combineReducers({
    count:countReducers,
    login:loginReducer,
})